package com.ruoyi.web.controller.laiqianba.channel;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.ChannelExtInfo;
import com.ruoyi.channel.service.IChannelExtInfoService;
import com.ruoyi.web.wrapper.ChannelExtInfoWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 渠道扩展信息Controller
 * 
 * @author ruoyi
 * @date 2023-11-13
 */
@RestController
@RequestMapping("/channel/channelExtInfo")
public class ChannelExtInfoController extends BaseController
{
    @Autowired
    private IChannelExtInfoService channelExtInfoService;

    /**
     * 查询渠道扩展信息列表
     */
    @PreAuthorize("@ss.hasPermi('channel:channelExtInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChannelExtInfo channelExtInfo)
    {
        startPage();
        List<Map<String, Object>> list = channelExtInfoService.selectChannelExtInfoMapList(channelExtInfo);
        list = new ChannelExtInfoWrapper(list).wrap();
        return getDataTable(list);
    }

    /**
     * 导出渠道扩展信息列表
     */
    @PreAuthorize("@ss.hasPermi('channel:channelExtInfo:export')")
    @Log(title = "渠道扩展信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChannelExtInfo channelExtInfo)
    {
        List<ChannelExtInfo> list = channelExtInfoService.selectChannelExtInfoList(channelExtInfo);
        ExcelUtil<ChannelExtInfo> util = new ExcelUtil<ChannelExtInfo>(ChannelExtInfo.class);
        util.exportExcel(response, list, "渠道扩展信息数据");
    }

    /**
     * 获取渠道扩展信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('channel:channelExtInfo:query')")
    @GetMapping(value = "/{channelCode}")
    public AjaxResult getInfo(@PathVariable("channelCode") String channelCode)
    {
        ChannelExtInfo channelExtInfo = channelExtInfoService.selectChannelExtInfoByChannelCode(channelCode);
        if (StrUtil.isNotEmpty(channelExtInfo.getZhimaFilter())){
            channelExtInfo.setZhimaFilterArray(JSON.parseArray(channelExtInfo.getZhimaFilter()));
        }else {
            channelExtInfo.setZhimaFilterArray(new JSONArray());
        }
        return success(channelExtInfo);
    }

    /**
     * 新增渠道扩展信息
     */
    @PreAuthorize("@ss.hasPermi('channel:channelExtInfo:add')")
    @Log(title = "渠道扩展信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChannelExtInfo channelExtInfo)
    {
        return toAjax(channelExtInfoService.insertChannelExtInfo(channelExtInfo));
    }

    /**
     * 修改渠道扩展信息
     */
    @PreAuthorize("@ss.hasPermi('channel:channelExtInfo:edit')")
    @Log(title = "渠道扩展信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChannelExtInfo channelExtInfo)
    {
        return toAjax(channelExtInfoService.updateChannelExtInfo(channelExtInfo));
    }

    /**
     * 删除渠道扩展信息
     */
    @PreAuthorize("@ss.hasPermi('channel:channelExtInfo:remove')")
    @Log(title = "渠道扩展信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{channelCodes}")
    public AjaxResult remove(@PathVariable String[] channelCodes)
    {
        return toAjax(channelExtInfoService.deleteChannelExtInfoByChannelCodes(channelCodes));
    }
}
